package com.stylefeng.guns.modular.salesmanagement.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.modular.system.model.CustomerReturnList;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.GoodsSaleList;
import com.stylefeng.guns.modular.salesmanagement.service.IGoodsSaleListService;

/**
 * 销售单据查询控制器
 *
 * @author fengshuonan
 * @Date 2018-09-12 21:26:32
 */
@Controller
@RequestMapping("/goodsSaleList")
public class GoodsSaleListController extends BaseController {

    private String PREFIX = "/salesmanagement/goodsSaleList/";

    @Autowired
    private IGoodsSaleListService goodsSaleListService;

    /**
     * 跳转到销售单据查询首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "goodsSaleList.html";
    }

    /**
     * 跳转到添加销售单据查询
     */
    @RequestMapping("/goodsSaleList_detail/{saleGoodsId}/{saleOrderNumber}")
    public String goodsSaleListAdd(@PathVariable(value = "saleGoodsId") Long saleGoodsId,
                                   @PathVariable(value = "saleOrderNumber") String saleOrderNumber,
                                   Model model) {
        model.addAttribute("saleGoodsId", saleGoodsId);
        model.addAttribute("saleOrderNumber", saleOrderNumber);
        return PREFIX + "goodsSaleList_detail.html";
    }

    /**
     * 跳转到修改销售单据查询
     */
    @RequestMapping("/goodsSaleList_update/{goodsSaleListId}")
    public String goodsSaleListUpdate(@PathVariable Integer goodsSaleListId, Model model) {
        GoodsSaleList goodsSaleList = goodsSaleListService.selectById(goodsSaleListId);
        model.addAttribute("item",goodsSaleList);
        LogObjectHolder.me().set(goodsSaleList);
        return PREFIX + "goodsSaleList_edit.html";
    }

    /**
     * 获取销售单据查询列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return goodsSaleListService.selectList(null);
    }

    /**
     * 新增销售单据查询
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(GoodsSaleList goodsSaleList) {
        goodsSaleListService.insert(goodsSaleList);
        return SUCCESS_TIP;
    }

    /**
     * 删除销售单据查询
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer goodsSaleListId) {
        goodsSaleListService.deleteById(goodsSaleListId);
        return SUCCESS_TIP;
    }

    /**
     * 修改销售单据查询
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(GoodsSaleList goodsSaleList) {
        goodsSaleListService.updateById(goodsSaleList);
        return SUCCESS_TIP;
    }

    /**
     * 销售单据查询详情
     */
    @RequestMapping(value = "/detail/{goodsSaleListId}")
    @ResponseBody
    public Object detail(@PathVariable("goodsSaleListId") Long goodsSaleListId) {
        EntityWrapper<GoodsSaleList> entityWrapper = new EntityWrapper<>();
        entityWrapper.eq("goods_sale_id",goodsSaleListId);
        return goodsSaleListService.selectList(entityWrapper);
    }
}
